<template>
  <div class="container" style="width: 600px; margin-top: 150px">
    <div class="panel panel-default">
      <div class="panel-heading">登录</div>
      <div class="panel-body">
        <form>
          <div class="form-group">
            <label for="exampleInputEmail1">用户名</label>
            <input
              type="text"
              class="form-control"
              v-model="data.name"
              placeholder="用户名"
            />
          </div>
          <div class="form-group">
            <label for="exampleInputPassword1">密码</label>
            <input
              type="password"
              class="form-control"
              v-model="data.idcard"
              placeholder="密码"
            />
          </div>
          <div class="form-group">
            <label class="radio-inline">
              <input
                type="radio"
                name="inlineRadioOptions"
                v-model="data.identity"
                value="1"
              />
              接种用户
            </label>
            <label class="radio-inline">
              <input
                type="radio"
                name="inlineRadioOptions"
                v-model="data.identity"
                value="0"
              />
              管理员
            </label>
          </div>
          <button type="button" class="btn btn-primary" @click="login">
            登录</button
          >&nbsp;&nbsp;
          <button type="reset" class="btn btn-default">重置</button>
        </form>
        <span>{{ msg }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      data: {
        name: "",
        idcard: "",
        identity: 1,
      },
      user: {},
      //登录提醒消息
      msg: "",
    };
  },
  methods: {
    //登录
    login() {
      console.log(
        this.data.name + " --- " + this.data.idcard + "---" + this.data.identity
      );

      this.$api_w
        ._api_login_usersjiezhong(this.data)
        .then((response) => {
          console.log(response);
          this.user = response;
          console.log(this.data.identity);
          if (this.data.identity == 0) {
            console.log("管理员");
            //管理员
            this.$router.push("/index");
          } else if (this.data.identity == 1) {
            //用户
            this.$router.push({
              path: "/user",
              query: { nameId: this.user[0].id },
            });
          }
        })
        .catch((error) => {
          
        });

      //   this.axios.get("http://localhost:3000/userjiezhong?name=" + this.data.name + "&shenfen=" + this.data.idcard).then((response)=>{
      //     this.user = response.data;
      //     console.log(this.user)
      //     if(response.status >= 200 && response.status <300){
      //         //登录成功
      //         if(this.data.identity == 0){
      //           console.log("管理员")
      //           //管理员
      //           this.$router.push("/index")
      //         }else if(this.data.identity == 1) {
      //           //用户
      //          this.$router.push({ path: "user", query:{shenfen:this.user.shenfen} });
      //         }
      //       }else{
      //         //失败
      //         this.msg = "用户名密码错误";
      //       }
      //   }).catch((error)=>{
      //     this.msg = error;
      //   })
    },
    //登录结束
  },
};
</script>
